package cate.game.chat.msg;

import cate.game.GameBody;
import cate.game.chat.ChatContentParam;
import cate.game.chat.ChatRequest;
import cate.game.client.ClientContext;
import cate.game.client.msg.ClientMsg;
import cate.game.client.msg.MsgConfig;
import cate.game.client.msg.MsgInput;
import cate.game.client.msg.id.MsgIdBChat;
import cate.game.role.Role;
import cp.solution.business.sys.env.EnvironmentVarSets;
import easy.java.dev.note.NoteField;
import org.apache.commons.lang3.StringUtils;

import java.util.List;

@ClientMsg(title = "发送到私聊频道 の 请求")
public class ChatSendPrivateReq implements MsgInput {
    @NoteField(value = "接受者的唯一ID")
    public String toId;

    @NoteField(value = "消息内容")
    public String content;

    @NoteField(value = "消息附加参数")
    public List<ChatContentParam> params;

    @NoteField(value = "消息内容验证")
    public String checkSign;

    @NoteField(value = "消息内容ID")
    public int contentId;

    @Override
    public void execute(GameBody game, ClientContext cc) {
        h(game, cc.getRole());
    }

    public void h(GameBody game, Role role) {
        if(EnvironmentVarSets.getInstance().isChatDisabled()) {
            game.notice.message(role, EnvironmentVarSets.getInstance().getChatDisabledAlert());
            return;
        }
        perform(game, role, () -> {
            if (StringUtils.isNotBlank(content)) {
                ChatRequest.checkSign(content, checkSign);
            }
            role.getChat().sendPrivate(toId, contentId, content, params);
        });
    }

    @Override
    public MsgConfig conf() {
        return MsgIdBChat.SEND_PRIVATE_REQ;
    }
}
